//
//  submitOrderViewController.m
//  giuseppe
//
//  Created by Apple on 15/8/18.
//  Copyright (c) 2015年 GiantUmbrella. All rights reserved.
//

#import "submitOrderViewController.h"
#import "define.h"
#import "addressListsViewController.h"
#import "PaymentViewController.h"

@interface submitOrderViewController ()<UITableViewDataSource,UITableViewDelegate>{
    UITableView *_tableView;
}

@end

@implementation submitOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController setToolbarHidden:YES animated:YES];
    
    
    //自定义的导航栏
    UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];
    navView.backgroundColor = [UIColor whiteColor];
    navView.alpha = 0.90;
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(10, 33, 27, 16);
    [backButton setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth/2-50, 20, 100, 40)];
    titleLabel.text = @"确认订单";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    

    [self _initView];
    
    [navView addSubview:backButton];
    [navView addSubview:titleLabel];
    [self.view addSubview:navView];

    
}


- (void)_initView{
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight-64)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    
    UIView *payView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenHeight-64, kScreenWidth, 64)];
    payView.backgroundColor = [UIColor whiteColor];
    
    UILabel *totalLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 20, 60, 30)];
    totalLabel.text = @"总金额:";
    
    [payView addSubview:totalLabel];
    
    UILabel *priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth-150, 20, 60, 30)];
    priceLabel.text = @"998";
    priceLabel.textColor = mainColor;
    
    [payView addSubview:priceLabel];
    
    
    UIButton *payButton = [UIButton buttonWithType:UIButtonTypeCustom];
    payButton.frame = CGRectMake(kScreenWidth-70, 25, 60, 25);
    payButton.backgroundColor = mainColor;
    [payButton setTitle:@"确认支付" forState:UIControlStateNormal];
    payButton.titleLabel.adjustsFontSizeToFitWidth = YES;
    [payButton addTarget:self action:@selector(pay) forControlEvents:UIControlEventTouchUpInside];
    
    [payView addSubview:payButton];
    
    
    [self.view addSubview:payView];
    
    
}

#pragma mark--- tableViewDelegate 每个区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return 4;
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        return 40;
    }if (indexPath.row == 1) {
        return 90;
    }if (indexPath.row == 2){
        return 40;
    }else{
        return 200;
    }
    
}


#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
    
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        NSString *labelText = @"收货地址";
        cell.textLabel.text = labelText;
        return cell;

    }if (indexPath.row == 2) {
        
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        NSString *labelText = @"商品";
        cell.textLabel.text = labelText;
        return cell;
        
    }if (indexPath.row == 1) {
        
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

        UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 10, kScreenWidth-15, 10)];
        
        UILabel *mobileLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 30, kScreenWidth-15, 10)];
        
        UILabel *addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 50, kScreenWidth-15, 10)];
        
        UILabel *postCodeLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 70, kScreenWidth-15, 10)];
        
        nameLabel.font = [UIFont systemFontOfSize:13];
        mobileLabel.font = [UIFont systemFontOfSize:13];
        addressLabel.font = [UIFont systemFontOfSize:13];
        postCodeLabel.font = [UIFont systemFontOfSize:13];
        
        nameLabel.text = @"小明";
        mobileLabel.text = @"13023660332";
        addressLabel.text = @"浙江省杭州市西湖区文新街道古墩路98号西城新座16D";
        postCodeLabel.text = @"310013";
        
        [cell.contentView addSubview:nameLabel];
        [cell.contentView addSubview:mobileLabel];
        [cell.contentView addSubview:addressLabel];
        [cell.contentView addSubview:postCodeLabel];
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;

    }else{
        
        
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        
        

        UIScrollView *orderListScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 200)];
        
        orderListScrollView.contentSize = CGSizeMake(kScreenWidth*2, 200);
        

        

        

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
        

    }

    

    
}


#pragma mark--- tableViewDelegat 点击方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    if (indexPath.row == 1) {
        addressListsViewController *addressListsVC = [[addressListsViewController alloc]init];
        [self.navigationController pushViewController:addressListsVC animated:YES];
    }
    
}

- (void)pay{
    
    PaymentViewController *paymengVC = [[PaymentViewController alloc]init];
    [self.navigationController pushViewController:paymengVC animated:YES];

                                        
}

- (void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
